<template>
  <div class="login-card">
    <h3>{{ getRoleName }}登录</h3>
    <div class="my-input">
      <label>
        <input v-model="formLogin.username" autocomplete="off" name="username"
               placeholder="username"
               style="background-image: url('/icon/username.svg')" type="text">
        <span>帐号</span>
      </label>
    </div>
    <div class="my-input">
      <label>
        <input v-model="formLogin.password" name="password" placeholder="password"
               style="background-image: url('/icon/password.svg')" type="password"
               @keyup.enter="toLogin"
        >
        <span>密码</span>
      </label>
    </div>
    <div class="remember">
      <label class="check-label">
        <input v-model="formLogin.remember" class="check-input" name="remember" type="checkbox">
        <span class="check-block">
          <span class="inner">记住我</span>
        </span>
      </label>
    </div>
    <MyBtn @click="toLogin">登录</MyBtn>
  </div>
</template>

<script lang="ts" setup>
/*=====登录的页面，不同的角色同一个登录页面，不同的请求路径=====*/
import {computed, reactive} from "vue";
import MyBtn from "@/components/button/MyBtn.vue";
import {reqLogin} from "@/request/PowerApi";
import {LoginVo, RoleEnum} from "@/model/VO/LoginVo";
// 定义登录的角色
const prop = defineProps<{
  role: RoleEnum
}>()
// 登陆成功的事件
const emit = defineEmits<{
  (e: "loginSuc"): void
}>()
// 根据传来的角色设置展示
const getRoleName = computed(() => {
  switch (prop.role) {
    case RoleEnum.DOCTOR:
      return "医生";
    default:
      return "用户";
  }
})
// 登录的数据
const formLogin: LoginVo = reactive({
  username: "",
  password: "",
  remember: true,
  role: RoleEnum.CLIENT
})

// 点击登录之后
const toLogin = () => {
  formLogin.role = prop.role
  reqLogin(formLogin).then(resp => {
    console.log(resp.msg)
    if (resp.code == 1) {
      emit("loginSuc")
    }
  })
}
</script>

<style lang="scss" scoped>
/* 粉色调登录卡片 */
.login-card {
  width: 320px;
  text-align: center;
  background: linear-gradient(145deg, #fff5f5, #ffebf1);
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(255, 105, 180, 0.2);

  h3 {
    color: #ff6b9a;
    margin-bottom: 25px;
    font-size: 22px;
    font-weight: 600;
  }
}

/* 粉色浮动输入框 */
.my-input {
  position: relative;
  text-align: left;
  margin: 15px 0;

  label {
    display: block;
    position: relative;

    input {
      transition: all 0.3s ease;
      width: 90%;
      height:32px;
      padding: 10px 0 0 42px;
      border: 2px solid #ffd6e7;
      border-radius: 12px;
      background: {
        size: 20px;
        repeat: no-repeat;
        position: 12px center;
        color: #fff;
      };
      font-size: 14px;
      color: #ff6b9a;

      &[type="text"] {
        background-image: url('/icon/username.svg');
      }

      &[type="password"] {
        background-image: url('/icon/password.svg');
      }

      &::placeholder {
        color: transparent;
      }

      &:focus {
        border-color: #ff9ec6;
        box-shadow: 0 0 0 3px rgba(255, 155, 193, 0.3);
        background-color: #fff9fb;
      }

      &:not(:placeholder-shown) + span,
      &:focus + span {
        color: #ff4785;
        transform: scale(0.75) translateY(-10px) translateX(-10px);
      }
    }

    span {
      position: absolute;
      font-size: 14px;
      color: #ff9ec6;
      top: 12px;
      left: 42px;
      transition: all 0.3s ease;
      pointer-events: none;
    }
  }
}

/* 粉色记住我复选框 */
.remember {
  margin: 20px 0;
  text-align: left;

  .check-label {
    display: inline-flex;
    align-items: center;
    cursor: pointer;

    .check-input {
      display: none;

      &:checked + .check-block {
        background-color: #ff6b9a;
        box-shadow: 0 2px 8px rgba(255, 107, 154, 0.4);

        .inner {
          color: white;
        }
      }
    }

    .check-block {
      display: inline-flex;
      align-items: center;
      padding: 6px 12px;
      border-radius: 20px;
      background-color: #ffebf1;
      transition: all 0.3s ease;

      .inner {
        color: #ff6b9a;
        font-size: 13px;
        transition: color 0.3s ease;
      }
    }
  }
}

/* 粉色登录按钮 */
.my-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(to right, #ff6b9a, #ff8fab);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(255, 107, 154, 0.3);

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(255, 107, 154, 0.4);
  }

  &:active {
    transform: translateY(0);
  }
}
</style>
